
$(document).ajaxSend(function(event, request, settings) {

	var url = settings.url;
	// if (url.indexOf("?") >= 0) {
	// url = url + "&timstamp=" + now();
	//        
	// } else {
	// url = url + "?timstamp=" + now();
	// }
	settings.url = url;
});

$(document).ajaxError(function(event, request, settings) {
	showErrorWin(request.responseText);
});


function showInfoWin(msgString, fn) {
	alert(msgString);

}


function showErrorWin(msgString, fn) {
	alert(msgString);
}


function now() {
	return (new Date).getTime();
}



var $dialog;

function openWin(theURL, winName, sizeType, width, height, scrol, resizable) {

	var winWidth = 0;
	var winHeight = 0;

	if (sizeType == null || sizeType == "") {
		winWidth = 800;
		winHeight = 600;
	} else if (sizeType == 'A0') {
		winWidth = width;
		winHeight = height;
	} else if (sizeType == 'A1') {
		winWidth = 600;
		winHeight = 450;
	} else if (sizeType == 'A2') {
		winWidth = 800;
		winHeight = 600;
	} else if (sizeType == 'A3') {
		winWidth = 900;
		winHeight = 650;
	}

	$dialog = $('<div id="dialog_iframe_win"></div>').html('<iframe style="border: 0px; " src="' + theURL + '" width="100%" height="100%"></iframe>').dialog({
		autoOpen : false,
		modal : true,
		height : winHeight,
		width : winWidth,
		title : '' //winName don't show title
	});
	$dialog.dialog('open');
}

/**
 * close window
 * <p>
 */
function closeWin() {
	parent.$dialog.dialog('destroy');
}


function getOpenerWin() {

	return window.opener;
}


function refreshWin() {
	window.location.reload();
}


$.fn.serializeObject = function() {
	var o = {};
	var a = this.serializeArray();
	$.each(a, function() {
		if (o[this.name]) {
			if (!o[this.name].push) {
				o[this.name] = [ o[this.name] ];
			}
			o[this.name].push(this.value || '');
		} else {
			o[this.name] = this.value || '';
		}
	});
	return o;
};

function showSystemProccessing() {
	var wrap = $(document.body);

	$('<div class="system-processing-mask"></div>').css({
		display : 'block',
		width : wrap.width() - 22,
		height : wrap.height() - 10
	}).appendTo(wrap);

	$('<div class="system-processing-msg"></div>').html('正在处理，请稍待。。。').appendTo(wrap).css({
		display : 'block',
		left : (wrap.width() - $('.system-processing-msg').outerWidth()) / 2,
		top : (wrap.height() - $('.system-processing-msg').outerHeight()) / 2
	});

	
}

function removeSystemProccessing() {
	$('.system-processing-mask').remove();
	$('.system-processing-msg').remove();

}


function showModalWin(action, sizeType, width, height) {

	var dialogWidth = 0;
	var dialogHeight = 0;

	if (sizeType == null || sizeType == "") {
		dialogWidth = 450;
		dialogHeight = 450;
	} else if (sizeType == 'A0') {
		dialogWidth = width;
		dialogHeight = height;
	} else if (sizeType == 'A1') {
		dialogWidth = 450;
		dialogHeight = 450;
	} else if (sizeType == 'A2') {
		dialogWidth = 800;
		dialogHeight = 600;
	}

	if (isEmpty(action)) {
		showInfoWin('请输入弹出模态窗口的action！');
	}

	if (action.indexOf("?") >= 0) {
		action = action + "&timstamp=" + now();

	} else {
		action = action + "?timstamp=" + now();
	}
	return window.showModalDialog(action, 'select', 'dialogWidth=' + dialogWidth + 'px;dialogHeight=' + dialogHeight + 'px;help=no;resizable=no;status=no');
}
